package com.beardedhen.harmonybootstrap.api.defaults;



import com.beardedhen.harmonybootstrap.utils.ResUtil;
import com.beardedhen.harmonybootstrap.ResourceTable;
import com.beardedhen.harmonybootstrap.api.attributes.BootstrapBrand;
import com.beardedhen.harmonybootstrap.utils.ColorUtils;

import ohos.app.Context;

import static com.beardedhen.harmonybootstrap.utils.ColorUtils.*;

/**
 * Bootstrap provides 6 brands by default - Primary, Success, Info, Warning, Danger, and Default.
 * Brands are often supplemented by view-specific colors, which are <b>not</b> globally used.
 */
public enum DefaultBootstrapBrand implements BootstrapBrand {

    PRIMARY(ResourceTable.Color_bootstrap_brand_primary),
    SUCCESS(ResourceTable.Color_bootstrap_brand_success),
    INFO(ResourceTable.Color_bootstrap_brand_info),
    WARNING(ResourceTable.Color_bootstrap_brand_warning),
    DANGER(ResourceTable.Color_bootstrap_brand_danger),
    SECONDARY(ResourceTable.Color_bootstrap_brand_secondary_fill, ResourceTable.Color_bootstrap_brand_secondary_text),
    REGULAR(ResourceTable.Color_bootstrap_gray_light);

    private final int textColor;
    private final int color;

    DefaultBootstrapBrand(int color) {
        this.color = color;
        this.textColor = com.beardedhen.harmonybootstrap.ResourceTable.Color_white;
    }

    DefaultBootstrapBrand(int color, int textColor) {
        this.color = color;
        this.textColor = textColor;
    }

    public static DefaultBootstrapBrand fromAttributeValue(int attrValue) {
        switch (attrValue) {
            case 0:
                return PRIMARY;
            case 1:
                return SUCCESS;
            case 2:
                return INFO;
            case 3:
                return WARNING;
            case 4:
                return DANGER;
            case 5:
                return REGULAR;
            case 6:
                return SECONDARY;
            default:
                return REGULAR;
        }
    }

    @Override
    public int defaultFill(Context context) {
        return ResUtil.getColor(context, color);
    }

    @Override public int defaultEdge(Context context) {
        return decreaseRgbChannels(context, color, ACTIVE_OPACITY_FACTOR_EDGE);
    }

    @Override
    public int defaultTextColor(Context context) {
        return ResUtil.getColor(context, textColor);
    }

    @Override
    public int activeFill(Context context) {
        return decreaseRgbChannels(context, color, ACTIVE_OPACITY_FACTOR_FILL);
    }

    @Override
    public int activeEdge(Context context) {
        return decreaseRgbChannels(context, color, ACTIVE_OPACITY_FACTOR_FILL + ACTIVE_OPACITY_FACTOR_EDGE);
    }

    @Override
    public int activeTextColor(Context context) {
        return ColorUtils.resolveColor(textColor,context);
    }

    @Override
    public int disabledFill(Context context) {
        return ColorUtils.increaseOpacityFromInt(context, ResUtil.getColor(context, color), DISABLED_ALPHA_FILL);
    }

    @Override
    public int disabledEdge(Context context) {
        return ResUtil.getColor(context, color);
    }

    @Override
    public int disabledTextColor(Context context) {
        return ColorUtils.resolveColor(textColor,context);
    }

    @Override
    public int getColor() {
        return color;
    }

}